App = Ember.Application.create({});

var currency_pairs = [{
  id: '1',
  name: 'EUR/USD',
  sell_price: 1.35216,
  buy_price:  1.35277,
  pip: 10000
}, {
  id: '2',
  name: 'USD/JPY',
  sell_price: 101.296,
  buy_price:  101.394,
  pip: 100
},{
  id: '1',
  name: 'EUR/USD',
  sell_price: 1.35216,
  buy_price:  1.35277,
  pip: 10000
}, {
  id: '2',
  name: 'USD/JPY',
  sell_price: 101.296,
  buy_price:  101.394,
  pip: 100
},{
  id: '1',
  name: 'EUR/USD',
  sell_price: 1.35216,
  buy_price:  1.35277,
  pip: 10000
}, {
  id: '2',
  name: 'USD/JPY',
  sell_price: 101.296,
  buy_price:  101.394,
  pip: 100
},{
  id: '1',
  name: 'EUR/USD',
  sell_price: 1.35216,
  buy_price:  1.35277,
  pip: 10000
}, {
  id: '2',
  name: 'USD/JPY',
  sell_price: 101.296,
  buy_price:  101.394,
  pip: 100
}];

var history_lots = [{
  id: '1',
  name: 'GPB/JPY',
  type: 'buy',
  lots: '0.01',
  opened_at: '2014-07-21 12:13:25',
  closed_at: '2014-07-21 12:18:25',
  opened_price: '173.013',
  closed_price: '173.038',
  highest_pips: '412',
  lowest_pips: '-213',
  earn_pips: '167.1',
  earn_dollar: '412.00',
  totol_pips: '-82',
  total_dollar: '143.00',

},{
  id: '2',
  name: 'USD/JPY',
  type: 'sell',
  lots: '0.03',
  opened_at: '2014-07-25 12:13:25',
  closed_at: '2014-07-26 15:18:20',
  opened_price: '173.013',
  closed_price: '171.038',
  highest_pips: '112',
  lowest_pips: '-313',
  earn_pips: '-167.1',
  earn_dollar: '-12.00',
  totol_pips: '82',
  total_dollar: '-163.00',
  
}];


App.Router.map(function() {
  this.resource('trader');
  this.resource('history');
});

App.TraderRoute = Ember.Route.extend({
  model: function(){
    return currency_pairs;
  }
});

App.HistoryController = Ember.ArrayController.extend({

  // count: function(){
  //   return this.get(length);
  // }.property(@each)
})

App.LotItemController = Ember.ObjectController.extend({
  isWin: function(){
    if(this.get("opened_price") > this.get("closed_price"))
      {return false;}
    else
      {return true;}
  }.property('isWin')
})

App.HistoryRoute = Ember.Route.extend({
  model: function(){
    return history_lots;
  }
});

Ember.Handlebars.helper('CalculateSpread', function(buy_price, sell_price, pip){
  return new Handlebars.SafeString(((parseFloat(buy_price) - parseFloat(sell_price))*pip).toFixed(1));
});
